package com.sw.small_world.utils;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;


/**
 * Created by zs on 2016/4/1.
 */
public class DialogUtils {

    public static void showPermissionDialog(final Activity context, int resId) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle("权限申请");
        builder.setMessage(CommonUtils.getString(resId));
        builder.setPositiveButton("去设置", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent();
                intent.setAction("android.intent.action.MAIN");
                intent.setClassName("com.android.settings", "com.android.settings.ManageApplications");
                context.startActivityForResult(intent, ConstantUtils.CODE_PERMISSION);
                dialog.dismiss();
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.show();
    }

    public static void showPermissionDialog(final Activity context, int resId, final Fragment fragment) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle("权限申请");
        builder.setMessage(CommonUtils.getString(resId));
        builder.setPositiveButton("去设置", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent();
                intent.setAction("android.intent.action.MAIN");
                intent.setClassName("com.android.settings", "com.android.settings.ManageApplications");
                fragment.startActivityForResult(intent, ConstantUtils.CODE_PERMISSION);
                dialog.dismiss();
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.show();
    }
}
